package com.sf.marathon.soul.core.base;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
import com.sf.marathon.soul.core.constant.Constans;
import com.sf.marathon.soul.core.util.SignUtils;

/**
 * Created by 01368146 on 2017/12/14.
 */
@Controller
@RequestMapping("/token")
public class TokenController {

    @RequestMapping("/clearAll")
    @ResponseBody
    public String clearAll() {
        SignUtils.xTokens.clear();
        return Constans.SUCCESS;
    }

    @RequestMapping("/clear")
    @ResponseBody
    public String clear(@RequestParam("id") String id) {
        SignUtils.xTokens.remove(id);
        return Constans.SUCCESS;
    }

    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> list() {
        Map<String, Object> resultMap = Maps.newHashMap();
        resultMap.put("tokens", SignUtils.xTokens);
        resultMap.put("total", SignUtils.xTokens.size());
        return resultMap;
    }
}
